package com.ruyuan.commodity.consumer.core.consumer.goods;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.hutool.json.JSONUtil;
import com.ruyuan.commodity.consumer.core.event.GoodsSkuChangeEvent;
import com.ruyuan.commodity.open.api.client.promotion.api.AssociationGroupGoodsOpenApi;
import com.ruyuan.commodity.open.api.client.promotion.domain.DelAssociationGoodsRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 删除促销活动商品
 */
@Component
public class PromotionGoodsChangeConsumer implements GoodsSkuChangeEvent {

    @Autowired
    private AssociationGroupGoodsOpenApi associationGroupGoodsOpenApi;

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void goodsSkuChange(List<Long> delSkuIds) {
        // 删除促销活动商品
        DelAssociationGoodsRequest request = new DelAssociationGoodsRequest();
        request.setDelSkuIds(delSkuIds);
        associationGroupGoodsOpenApi.deletePinTuanGoods(JSONUtil.toJsonStr(request));
        // 删除拼团商品
        DelAssociationGoodsRequest delAssociationGoodsRequest = new DelAssociationGoodsRequest();
        associationGroupGoodsOpenApi.deletePinTuanGoods(JSONUtil.toJsonStr(delAssociationGoodsRequest));
    }

}